<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
//pre(app::$__appData['componenterr']);
?>

<div id="hidden_content" <?php if($action !='install'):?>class="displaynone"<?php endif; ?>">
<?php App::Helper('Toolbar')->setTitle('Install Components')->setBtnBack()->Render(array('code'=>'install_component_top')); ?>
<br class="clearboth" />
<?php if(isset($message)){ echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'success', 'message' => $message));}?>
<?php if( isset($error)){ echo $this->callElement('default/tools/message', array('caption' =>'Error','type' => 'error', 'message' => $error));}?>
<p>	Upload a component in ZIP format form your computer.</p>
<form method="post" action="<?php echo $this->baseUrl("/developer/components/addnew/install");?>" enctype="multipart/form-data">
<input type="file" name="data[Component][resourcefile]"  />
<input type="submit" name="submit" value="Install" class="app_button" />
</form><br />
<br class="clearboth" />
</div>
<?php App::Helper('Toolbar')->setTitle('Components')->setBtnBack()->setBtnCustomHTML(App::load("Helper/Html")->buttonTag("Button[Toggle]","Install Component",array("class"=>"installcomponent")))->Render(array('code'=>'component_list_top')); ?>
<br class="clearboth" />
<?php if(!empty(app::$__appData['componenterr'])):
foreach(app::$__appData['componenterr'] as $val):if(count($val)>1): ?>
<?php echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'message', 'message' => "<strong>{$val[0]} Message:</strong><br />{$val[1]}")); ?>
<?php endif;endforeach;endif; ?>
<?php
    $DataGrid = App::Module('DataGrid');
	foreach($componentlist['data'] as $component):
		if(empty($component['error']))
		{
				$color = (strtolower($component['status']) == 'active') ? '#40BF00' : '#FF0000';
				$statustext = (strtolower($component['status']) == 'active') ? 'Deactivate' : 'Activate';
				$DataGrid->addRow("
								  <div class=\"c_node\">
									<p><strong style=\"font-size:12px\"><a name=\"{$component['namespace']}\">{$component['name']}</a></strong></p>
									" . App::Helper('Utility')->codeFormated($component['description']) . "<br /><br />
									Version:{$component['version']}  |	<a href=\"{$component['author_uri']}\">{$component['author']}</a> | <a href=\"{$component['author_uri']}\">{$component['uri']}</a>
									<p>
										<strong>" . App::Helper('Html')->linkTag($this->baseUrl("/developer/components/{$component['namespace']}/changestatus{$paginglink}"),$this->__(strtoupper($statustext)),array('style'=>"color:{$color}")) . "</strong> |
										<strong>" . App::Helper('Html')->linkTag("javascript:void(0)",$this->__("HELP"),array("class"=>"c_help","id"=>"{$component['namespace']}help")) . "</strong> |
										<strong>" . App::Helper('Html')->linkTag("javascript:void(0)",$this->__("REMOVE"),array("class"=>"removecomponent", "id"=>"{'component':'{$component['namespace']}'}")) . "</strong>
									</p>
									<div id=\"{$component['namespace']}helptext\" class=\"displaynone\"><p>{$component['help']}</p></div>
									</div>
								  ");
		}
		else
		{
				$DataGrid->addRow(
						  "<p><strong><a name=\"{$component['namespace']}\">{$component['name']}</a></strong></p>" . $component['description'] . "<br /><br /> {$this->__('Version')}:{$component['version']}  | <a href=\"{$component['author_uri']}\">{$component['author']}</a> | <a href=\"{$component['author_uri']}\">{$component['uri']}</a><p style=\"color:red\"><strong >Component Errors:</strong><br />" . implode("<br />",$component['error']) . "</p>");
		}
	endforeach;
	if($componentlist['paging']!="")
	{
		$DataGrid->addRow('<div style="text-align:center">' . $componentlist['link'] . ' | ' . $componentlist['paging'] . '</div>');
	}
	$DataGrid->Render();
?>
<?php App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'component_list_bottom')); ?>
<script type="text/javascript">
    window.addEvent('domready', function()
    {	var options = {'HCIdPadding':'text'};
        $$('.c_help').addEvent('click', function()
        {
            var _Obj = $(this.get('id') + options.HCIdPadding);
			(_Obj.hasClass('displaynone')) ? _Obj.removeClass('displaynone') : _Obj.addClass('displaynone');
        });

		$$(".removecomponent").addEvent("click", function(e){
			if(confirm("Are you sure to remove this component?\nNote: The action can not be undone!\n\nPress Ok to continue and Cancel to keep as it is."))
			{
				var component = JSON.decode(this.get('id')).component;
				window.location = base + '/developer/components/' + component + '/remove';
			}
        });

        $$(".installcomponent").addEvent("click", function(e){
            if( $("hidden_content").getStyle("display") == 'none')
            {
                $("hidden_content").setStyle("display", "block");
            }
            else
            {

                $("hidden_content").setStyle("display", "none");
            }
        });
    });
</script>